﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NutriStat.Statistics;

namespace NutriStat
{   
    public partial class ChartOptionsDialog : NutriDialog
    {
        #region Data
        #region Protected Data
        #endregion Protected Data

        #region Private Data        
        private NutriConfig config;
        #endregion Private Data

        #region Internal Data        
        #endregion Internal Data
        #endregion Data

        public ChartOptionsDialog()
        {
            InitializeComponent();
        }

        public ChartOptionsDialog(NutriConfig mainConfig)
        {
            InitializeComponent();
            config = new NutriConfig(mainConfig);
        }

        protected internal override void ConfigureFormControls()
        {
            base.ConfigureFormControls();

            result = string.Empty;

            if (config.ReferenceType.Equals(GrowthReferenceTypes.CDC2000))
            {
                listBoxGraphType.Items.Add(MeasurementOptions.BMI.FullName);
                listBoxGraphType.Items.Add(MeasurementOptions.HCA.FullName);
                listBoxGraphType.Items.Add(MeasurementOptions.WH.FullName);
                listBoxGraphType.Items.Add(MeasurementOptions.WL.FullName);
                listBoxGraphType.Items.Add(MeasurementOptions.WA.FullName);
                listBoxGraphType.Items.Add(MeasurementOptions.HA.FullName);
                listBoxGraphType.Items.Add(MeasurementOptions.LA.FullName);
                listBoxGraphType.SelectedIndex = 0;
            }
            else if (config.ReferenceType.Equals(GrowthReferenceTypes.WHO2006))
            {
                listBoxGraphType.Items.Add(MeasurementOptions.BMI.FullName);
                listBoxGraphType.Items.Add(MeasurementOptions.HCA.FullName);
                listBoxGraphType.Items.Add(MeasurementOptions.WH.FullName);
                listBoxGraphType.Items.Add(MeasurementOptions.WL.FullName);
                listBoxGraphType.Items.Add(MeasurementOptions.WA.FullName);
                listBoxGraphType.Items.Add(MeasurementOptions.HA.FullName);
                listBoxGraphType.Items.Add(MeasurementOptions.LA.FullName);
                listBoxGraphType.Items.Add(MeasurementOptions.MUACA.FullName);
                listBoxGraphType.Items.Add(MeasurementOptions.SSFA.FullName);
                listBoxGraphType.Items.Add(MeasurementOptions.TSFA.FullName);
                listBoxGraphType.SelectedIndex = 0;
            }
            else if (config.ReferenceType.Equals(GrowthReferenceTypes.WHO2007))
            {
                listBoxGraphType.Items.Add(MeasurementOptions.BMI.FullName);                              
                listBoxGraphType.Items.Add(MeasurementOptions.WA.FullName);
                listBoxGraphType.Items.Add(MeasurementOptions.HA.FullName);
                listBoxGraphType.SelectedIndex = 0;
            }
            else if (config.ReferenceType.Equals(GrowthReferenceTypes.WHO1978))
            {                
                listBoxGraphType.Items.Add(MeasurementOptions.WA.FullName);
                listBoxGraphType.Items.Add(MeasurementOptions.WH.FullName);
                listBoxGraphType.Items.Add(MeasurementOptions.WL.FullName);
                listBoxGraphType.Items.Add(MeasurementOptions.HA.FullName);
                listBoxGraphType.Items.Add(MeasurementOptions.LA.FullName);
                listBoxGraphType.SelectedIndex = 0;
            }
        }

        private void ChartOptionsDialog_Load(object sender, EventArgs e)
        {
            //bool success = false;
            //success = LoadConfigFile();

            ConfigureFormControls();            
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            result = string.Empty;
            this.Close();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (listBoxGraphType.SelectedItem.Equals(MeasurementOptions.BMI.FullName))
                {
                    result = MeasurementOptions.BMI.Abbreviation;
                }
                else if (listBoxGraphType.SelectedItem.Equals(MeasurementOptions.HCA.FullName))
                {
                    result = MeasurementOptions.HCA.Abbreviation;
                }
                else if (listBoxGraphType.SelectedItem.Equals(MeasurementOptions.WH.FullName))
                {
                    result = MeasurementOptions.WH.Abbreviation;
                }
                else if (listBoxGraphType.SelectedItem.Equals(MeasurementOptions.WL.FullName))
                {
                    result = MeasurementOptions.WL.Abbreviation;
                }
                else if (listBoxGraphType.SelectedItem.Equals(MeasurementOptions.WA.FullName))
                {
                    result = MeasurementOptions.WA.Abbreviation;
                }
                else if (listBoxGraphType.SelectedItem.Equals(MeasurementOptions.HA.FullName))
                {
                    result = MeasurementOptions.HA.Abbreviation;
                }
                else if (listBoxGraphType.SelectedItem.Equals(MeasurementOptions.LA.FullName))
                {
                    result = MeasurementOptions.LA.Abbreviation;
                }
                else if (listBoxGraphType.SelectedItem.Equals(MeasurementOptions.SSFA.FullName))
                {
                    result = MeasurementOptions.SSFA.Abbreviation;
                }
                else if (listBoxGraphType.SelectedItem.Equals(MeasurementOptions.TSFA.FullName))
                {
                    result = MeasurementOptions.TSFA.Abbreviation;
                }
                else if (listBoxGraphType.SelectedItem.Equals(MeasurementOptions.MUACA.FullName))
                {
                    result = MeasurementOptions.MUACA.Abbreviation;
                }
                else
                {
                    result = string.Empty;
                }
            }
            catch 
            { 
            }

            this.Close();
        }
    }

    public class MeasurementOptions
    {
        /*
        public const string BMI = "Body mass index-for-age";
        public const string HCA = "Head circumference-for-age";
        public const string WH = "Weight-for-height";
        public const string WL = "Weight-for-length";
        public const string WA = "Weight-for-age";
        public const string HA = "Height-for-age";
        public const string LA = "Length-for-age";
        public const string MUACA = "Mid-upper arm circumference-for-age";
        public const string SSFA = "Subscapular skin fold-for-age";
        public const string TSFA = "Triceps skin fold-for-age";
        */
        public static MeasurementOption BMI = new MeasurementOption("Body mass index", "BMI", "Body mass index-for-age", "age");
        public static MeasurementOption HCA = new MeasurementOption("Head circumference", "HCA", "Head circumference-for-age", "age");
        public static MeasurementOption WH = new MeasurementOption("Weight-for-height", "WH", "Weight-for-height", "height");
        public static MeasurementOption WL = new MeasurementOption("Weight-for-length", "WL", "Weight-for-length", "length");
        public static MeasurementOption WA = new MeasurementOption("Weight-for-age", "WA", "Weight-for-age", "age");
        public static MeasurementOption HA = new MeasurementOption("Height-for-age", "HA", "Height-for-age", "age");
        public static MeasurementOption LA = new MeasurementOption("Length-for-age", "LA", "Length-for-age", "age");
        public static MeasurementOption MUACA = new MeasurementOption("Mid-upper arm circumference", "MUACA", "Mid-upper arm circumference-for-age", "age");
        public static MeasurementOption SSFA = new MeasurementOption("Subscapular skin fold", "SSFA", "Subscapular skin fold-for-age", "age");
        public static MeasurementOption TSFA = new MeasurementOption("Triceps skin fold", "TSFA", "Triceps skin fold-for-age", "age");
    }

    /// <summary>
    /// Objects of this class represent a measurement unit. For example, millimeters, kilograms,
    /// inches, liters, etc. This is used to present uniform naming and abbrevation conventions
    /// across all parts of the application.
    /// </summary>
    public class MeasurementOption
    {
        #region Data
        #region Protected Data
        #endregion Protected Data

        #region Private Data
        private string name;
        private string abbreviation;
        private string fullName;
        private string axis;
        #endregion Private Data;

        #region Internal Data
        #endregion Internal Data
        #endregion Data

        #region Constructors
        /// <summary>
        /// The constructor for MeasurementOption object.
        /// </summary>
        /// <param name="abbreviation">The option's desired abbreviation.</param>
        /// <param name="fullName">The option's desired full name.</param>
        /// <param name="name">The option's desired name.</param>
        /// <param name="axis">The x-axis along which the option is usually plotted. Typically age in months.</param>
        public MeasurementOption(string name, string abbreviation, string fullName, string axis)
        {
            #region Input Validation
            #endregion Input Validation

            Name = name;
            Abbreviation = abbreviation;
            FullName = fullName;
            Axis = axis;
        }
        #endregion Constructors

        #region Properties
        #region Public Properties
        /// <summary>
        /// Gets the name of the measurement option.
        /// </summary>
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }

        /// <summary>
        /// Gets the abbreviation for the option.
        /// </summary>
        public string Abbreviation
        {
            get
            {
                return abbreviation;
            }
            set
            {
                abbreviation = value;
            }
        }

        /// <summary>
        /// Gets the full name of the measurement option.
        /// </summary>
        public string FullName
        {
            get
            {
                return fullName;
            }
            set
            {
                fullName = value;
            }
        }

        /// <summary>
        /// Gets the axis along which this measurement is usually plotted. Almost always age (months) or height/length.
        /// </summary>
        public string Axis
        {
            get
            {
                return axis;
            }
            set
            {
                axis = value;
            }
        }
        #endregion Public Properties

        #region Protected Properties
        #endregion Protected Properties

        #region Private Properties
        #endregion Private Properties
        #endregion Properties

        #region Methods
        #region Public Methods
        /// <summary>
        /// The ToString() method for the Unit object. Returns the full name of the unit.
        /// </summary>
        /// <returns>string</returns>
        public override string ToString()
        {
            return FullName;
        }
        #endregion Public Methods

        #region Protected Methods
        #endregion Protected Methods

        #region Private Methods
        #endregion Private Methods
        #endregion Methods
    }
}
